#include <jsoncpp/json/json.h>
#include <iostream>
#include <mysql++/mysql++.h>
#include "util.hpp"
using namespace std;
int main()
{

    mysqlpp::Connection con(false);
    con.connect(database.c_str(), host_name.c_str(), user_name.c_str(), passwd.c_str(), port);
    mysqlpp::Query q = con.query("select * from forward_index");
    mysqlpp::StoreQueryResult res = q.store();
    if (res)
    {
        for (int i = 0; i < res.num_rows(); ++i)
        {
            mysqlpp::Row r = res[i];
            auto& id = r["id"];
            auto& title = r["title"];
            auto& content = r["content"];
            auto& url = r["url"];
            cout << "id: " << id << endl;
            cout << "title: " << title << endl;
            cout << "url: " << url << endl;
        }
    }
    else
        cerr << "failed to get: " << q.error() << endl;
    //     std::string s = "a";
    //     q << "insert into inverted_index (word) values (" << mysqlpp::quote << s << ");";
    //     std::cout << q.str() << endl;
    //     q.execute();
    //     q.clear();
    //     q << "delete from inverted_index";
    //     q.execute();
    // }
    // catch (const mysqlpp::Exception& e) {
    //     std::cerr << "MySQL++ Exception: " << e.what() << std::endl;
    //     return 1;

// Json::Value v;
// v["id"] = 1;
// v["name"] = "lzz";
// std::string s = ns_util::json_util::serialize(v);
// std::cout << s << std::endl;
    return 0;
}